package com.winshare.saleAssistant.controller;

import com.winshare.saleAssistant.domain.dto.req.*;
import com.winshare.saleAssistant.service.ProductModuleService;
import com.winshare.saleAssistant.util.LogicResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sys/product/module")
@CrossOrigin
@Api(value = "产品发布->栏目设置", description = "产品发布->栏目设置")
public class ProductModuleController {

    private final ProductModuleService productModuleService;

    public ProductModuleController(ProductModuleService productModuleService) {
        this.productModuleService = productModuleService;
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增栏目接口",notes = "新增栏目(产品发布->栏目设置)接口")
    public LogicResponse save(@RequestBody @Validated ProductModuleCreateDTO productModuleCreateDTO) {
        productModuleService.save(productModuleCreateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改栏目接口",notes = "修改栏目(产品发布->栏目设置)接口")
    public LogicResponse update(@RequestBody @Validated ProductModuleUpdateDTO productModuleUpdateDTO) {
        productModuleService.update(productModuleUpdateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除栏目接口",notes = "删除栏目(产品发布->栏目设置)接口")
    public LogicResponse delete(@RequestBody @Validated ProductModuleIdDTO productModuleIdDTO) {
        productModuleService.delete(productModuleIdDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/list")
    @ResponseBody
    @ApiOperation(value = "查询栏目列表接口",notes = "查询栏目(产品发布->栏目设置)列表接口")
    public LogicResponse queryProductModulePage(@RequestBody @Validated ProductModuleQueryDTO productModuleQueryDTO) {
        return LogicResponse.success(productModuleService.getProductModuleList(productModuleQueryDTO));
    }

    @PostMapping("/sort")
    @ApiOperation(value = "栏目顺序调整接口",notes = "产品顺序调整接口")
    public LogicResponse sort(@RequestBody @Validated ProductModuleSortDTO productModuleSortDTO) {
        productModuleService.updateProductModuleSort(productModuleSortDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/detail")
    @ApiOperation(value = "获取单个栏目详情")
    public LogicResponse getProductModuleDetail(@RequestBody @Validated BaseIdDTO baseIdDTO) {
        return LogicResponse.success(productModuleService.getProductModuleDetail(baseIdDTO));
    }

}
